package de.koller.singularity.engine.tile;

import de.koller.aframe.plain.Sprite;
import de.koller.oceanFramework.util.ColorIntUtil;
import de.koller.singularity.SNode;
import de.koller.singularity.engine.SEngine;

public class STile extends SNode {

	public final Sprite sprite = new Sprite( SEngine.TILE_SIZE, SEngine.TILE_SIZE );
	public final String typeName;
	private int color = 0xff000000;
	
	public STile( String typeName ) {
		this.typeName = typeName;
	}
	
	public void recalcColor() {
		int r = 0, g = 0, b = 0;
		for( int x = 0; x < sprite.width; x++ )
			for( int y = 0;  y < sprite.height; y++ ) {
				int c = sprite.raster.getColor( x, y );
				r += ColorIntUtil.getRValue( c );
				g += ColorIntUtil.getGValue( c );
				b += ColorIntUtil.getBValue( c );
			}
		
		r /= sprite.width*sprite.height;
		g /= sprite.width*sprite.height;
		b /= sprite.width*sprite.height;
		color = ColorIntUtil.getIntColor( 0xff, r, g, b );
	}

	public int getColor() {
		return color;
	}
	
}
